package com.demo.emr1;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.beetl.ext.jfinal.BeetlRender;

import com.demo.utils.MyConstants;
import com.jfinal.core.Controller;

public class Emr1Controller extends Controller {
	
	

	/**
	 * 生成首页列表的连接
	 * 使用了beetl模板引擎
	 */
	public void index(){
		String FOLDER = "emr1";
		String INDEX_HTML = "emr1index.html";
		String sp = File.separator;
		String w = "/";
		
		/**
		 * https://www.cnblogs.com/duoting/p/4141044.html
		 * 获取web目录的方法参考上面URL
		 */
		// HttpServletRequest cannot be resolved to a type: 需要引入servlet-api-2.5.jar
		String webpath = getRequest().getSession().getServletContext().getRealPath("");
		
		try {
			File file = new File(webpath + sp + FOLDER);
			if(file.isDirectory()){
				List<String> others = new ArrayList<String>();
				File[] allFiles = file.listFiles();
				if(null != allFiles){
					String filename = null;
					for(File item : allFiles){
						if(item.isDirectory()){
							continue;
						}
						filename = item.getName().trim();
						if( !filename.equals( INDEX_HTML ) ){
							others.add(filename);
						}
					}
				}
				setAttr("filelist", others);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		render(new BeetlRender(MyConstants.WEBAPP_GT, w + FOLDER + w + INDEX_HTML));
	}
	
}
